//
//  JCTabBarViewController.m
//  JCTabBarViewController
//
//  Created by CHAN on 2018/2/6.
//  Copyright © 2018年 KOOSPUR. All rights reserved.
//

#import "JCTabBarViewController.h"
#import "LLTabBar.h"
#import "MyNavigationViewController.h"
#import "YFSetUpViewController.h"
#import "YFSportViewController.h"
#import "YFTemplateController.h"
#import "YFThreeDViewController.h"

@interface JCTabBarViewController ()<LLTabBarDelegate, UITabBarControllerDelegate>
@property (nonatomic, strong) LLTabBar *myTabBar;
@end

@implementation JCTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    [self setupTabBar];
    [self setupTabBarItem];
    self.selectedIndex = 2;
}

- (void)setupTabBarItem{
    _myTabBar = [[LLTabBar alloc] initWithFrame:self.tabBar.bounds];
    _myTabBar.backgroundColor = [UIColor clearColor];
    _myTabBar.tabBarItemAttributes = @[@{kLLTabBarItemAttributeTitle :@"Club" ,
                                         kLLTabBarItemAttributeNormalImageName : @"club_unselect",
                                         kLLTabBarItemAttributeSelectedImageName : @"club_select",
                                         kLLTabBarItemAttributeType : @(LLTabBarItemNormal)},
                                       
                                       @{kLLTabBarItemAttributeTitle : @"Train",
                                         kLLTabBarItemAttributeNormalImageName : @"train_unselect",
                                         kLLTabBarItemAttributeSelectedImageName : @"train_select",
                                         kLLTabBarItemAttributeType : @(LLTabBarItemNormal)},
                                       
                                       @{kLLTabBarItemAttributeTitle : @"Home",
                                         kLLTabBarItemAttributeNormalImageName : @"home_unselect",
                                         kLLTabBarItemAttributeSelectedImageName : @"home_select",
                                         kLLTabBarItemAttributeType : @(LLTabBarItemRise)},
                                       
                                       @{kLLTabBarItemAttributeTitle : @"Real-Time 3D",
                                         kLLTabBarItemAttributeNormalImageName : @"3D_unselect",
                                         kLLTabBarItemAttributeSelectedImageName : @"3D_select",
                                         kLLTabBarItemAttributeType : @(LLTabBarItemNormal)},
                                       
                                       @{kLLTabBarItemAttributeTitle : @"Settings",
                                         kLLTabBarItemAttributeNormalImageName : @"setup_unselect",
                                         kLLTabBarItemAttributeSelectedImageName : @"setup_select",
                                         kLLTabBarItemAttributeType : @(LLTabBarItemNormal)}];
    _myTabBar.delegate = self;
    [self.tabBar addSubview:_myTabBar];
}

-(void)setupTabBar{
    
//    MyNavigationViewController *sensorNav = [[UIStoryboard storyboardWithName:@"Sensor" bundle:nil] instantiateInitialViewController];
    
    MyNavigationViewController *clubNav = [[UIStoryboard storyboardWithName:@"Clubs" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"ClubNavi"];
    
    YFTemplateController *templateVc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:NSStringFromClass([YFTemplateController class])];
    MyNavigationViewController *templateNav = [[MyNavigationViewController alloc] initWithRootViewController:templateVc];
    
    MyNavigationViewController *trainNav = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateInitialViewController];
    
    YFThreeDViewController *threeDVc = [[YFThreeDViewController alloc] initWithNibName:@"YFThreeDViewController" bundle:nil];
    MyNavigationViewController *threeDNav = [[MyNavigationViewController alloc] initWithRootViewController:threeDVc];
    
    YFSetUpViewController *setUpVc = [[YFSetUpViewController alloc] init];
    MyNavigationViewController *setUpNav = [[MyNavigationViewController alloc] initWithRootViewController:setUpVc];
    
//    MyNavigationViewController *starVideoNav = [[UIStoryboard storyboardWithName:@"StarVideos" bundle:nil] instantiateInitialViewController];
    
//    MyNavigationViewController *pyqNav = [[UIStoryboard storyboardWithName:@"Find" bundle:nil] instantiateInitialViewController];
    
    [self setViewControllers:@[clubNav,
                               templateNav,
                               trainNav,
                               threeDNav,
                               setUpNav]];
    
}

- (void)switchControllerIndex:(NSInteger)index{
    self.selectedIndex = index;
    for (NSInteger i = 0; i < _myTabBar.tabBarItems.count; i++) {
        LLTabBarItem *item = _myTabBar.tabBarItems[i];
        item.selected = NO;
        if (index == i) {
            item.selected = YES;
        }
    }
}

@end
